Skip to content

Add support for BINARY (BYTEA) column type in JdbcOAuth2AuthorizationService#2337

Open
s-chan-o wants to merge 1 commit into
spring-projects:mainfrom
s-chan-o:fix/jdbc-postgresql-bytea-support
Open

Add support for BINARY (BYTEA) column type in JdbcOAuth2AuthorizationService#2337
s-chan-o wants to merge 1 commit into
spring-projects:mainfrom
s-chan-o:fix/jdbc-postgresql-bytea-support

Conversation

@s-chan-o

Copy link
Copy Markdown

Problem

JdbcOAuth2AuthorizationService fails when PostgreSQL (or PostgreSQL-compatible databases such as AWS Aurora DSQL) is used as the backend store.

PostgreSQL represents binary data using the BYTEA type, which is reported by the JDBC driver as Types.BINARY (-2). The current implementation only handles Types.BLOB and Types.CLOB, so BYTEA columns cause data read/write failures.

Fixes gh-2321

Changes

Added Types.BINARY handling in three locations within JdbcOAuth2AuthorizationService:

Method Change
getLobValue Reads bytes and converts to String; trims trailing null bytes present in fixed-length BINARY columns
doSetValue Writes byte[] or String values via LobCreator for Types.BINARY parameters
mapToSqlParameter Converts String values to byte[] when the column type is Types.BINARY

Testing

  • Added custom-oauth2-authorization-schema-binary-data-type.sql with binary(10000) column definitions (HSQL equivalent of PostgreSQL BYTEA, mapping to Types.BINARY)
  • Added tableDefinitionWhenBinarySqlTypeThenAuthorizationUpdated() test following the same pattern as the existing CLOB test

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 27, 2026
…Service

PostgreSQL uses BYTEA for binary data, which is reported by the JDBC
driver as Types.BINARY (-2). The JdbcOAuth2AuthorizationService only
handled Types.BLOB and Types.CLOB, causing failures when used with
PostgreSQL (and compatible databases such as AWS Aurora DSQL).

This commit adds handling for Types.BINARY in three places:
- getLobValue: reads bytes and converts to String, trimming trailing
  null bytes that may be present with fixed-length BINARY columns
- doSetValue: writes byte[] or String values via the LobCreator
- mapToSqlParameter: converts String values to byte[] for BINARY columns

Fixes spring-projectsgh-2321

Signed-off-by: seungchan <s24041@gsm.hs.kr>
@s-chan-o s-chan-o force-pushed the fix/jdbc-postgresql-bytea-support branch from 2171724 to e117302 Compare June 4, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService should support postgres DB as an implementation

2 participants